/*
 *  main.cpp
 *  sample
 *
 *  Created by jin on 1/1/11.
 *  Copyright 2011 __MyCompanyName__. All rights reserved.
 *
 */

#include "stdio.h"
#include <iostream>

#include <app.h>
#include <window.h>
#include <graphic2D.h>
#include <mouseEvent.h>
#include <assert.h>

class MyWindow : public Window
{
public:
    virtual void OnPaint(Graphic2D& gc);
    virtual void OnMouseDown(MouseEvent& evt);
    virtual void OnMouseMove(MouseEvent& evt);
    virtual void OnMouseUp(MouseEvent& evt);
};

void MyWindow::OnPaint(Graphic2D& gc)
{
    gc.clear_rect(0, 0, 100, 100);
    gc.draw_line(0, 0, 200, 300);
    gc.draw_line(200, 300, 300, 200);
}


void MyWindow::OnMouseDown(MouseEvent& evt)
{
    char buff[1024];
    sprintf(buff, "mouse down : %d, %d\n", evt.x, evt.y);
#ifdef WIN32
    OutputDebugStringA(buff);
#else
	printf(buff);
#endif
}


void MyWindow::OnMouseMove(MouseEvent& evt)
{
    char buff[1024];
    sprintf(buff, "mouse move : %d, %d\n", evt.x, evt.y);
#ifdef WIN32
    OutputDebugStringA(buff);
#else
	printf(buff);
#endif
}

void MyWindow::OnMouseUp(MouseEvent& evt)
{
    char buff[1024];
    sprintf(buff, "mouse up : %d, %d\n", evt.x, evt.y);
#ifdef WIN32
    OutputDebugStringA(buff);
#else
	printf(buff);
#endif
}

class minimalApp : public AppBase
{
public:
    virtual bool OnInit();
};

DECLARE_APP(minimalApp)
IMPLEMENT_APP(minimalApp)

bool minimalApp::OnInit()
{
    if (!AppBase::OnInit())
        return false;

    Window* win = new MyWindow;
#ifdef WIN32
    // sample of get native window handle
    HWND hwd = (HWND)win->GetHandle();
    ::ShowWindow(hwd, SW_SHOWMAXIMIZED);
#else
    win->Show();
#endif

    minimalApp* theApp = dynamic_cast<minimalApp*>(miniGetApp());
    assert(theApp != NULL);

    return true;
}




